/**
 * Created by lsq on 2017/12/5.
 */
import Sequelize from 'sequelize';


let server_config = {
    dbName:'hungrycell_data',
    user:'hungrycell',
    password:'iflytek-hungrycell',
    host:'121.199.25.9',
    port: 3310,
};

// let server_config = {
//     dbName:'hungrycell',
//     user:'migu',
//     password:'iflytek123456',
//     host:'172.16.4.196',
//     port: 3310,
// };

let sequelize = new Sequelize(server_config.dbName, server_config.user, server_config.password, {
    host: server_config.host,
    port: server_config.port,
    dialect: 'mysql',

    pool: {
        max: 5,
        min: 1,
        acquire: 10000,
        idle: 10000
    },

    timezone : '+08:00',
});


sequelize.authenticate()
    .then(() => {
        console.log('Connection has been established successfully.');
    })
    .catch(err => {
        console.error('Unable to connect to the database:', err);
    });


// let entityPath = path.resolve(__dirname, '../entity');
// fs.readdir(entityPath, function (err, files) {
//     if (err) {
//         return console.error(err);
//     }
//     files.forEach(function (file) {
//         let entity = require(entityPath + "/" + file);
//         sequelize.define(entity.tableName, entity.attributes, entity.options);
//     });
//
//     sequelize.models['report_hour'].findById(1).then(result => {
//         console.log(result);
//     });
// });

module.exports = sequelize;